package Demo02;

public enum TestEnum {
    RED(1,"红色"),
    BLACK(2,"黑色"),
    WHITE(3,"白色"),
    GREEN(4,"绿色");
    private int num;
    private String s;

    TestEnum(int num, String s) {
        this.num = num;
        this.s = s;
    }

    public static void main(String[] args) {
        //values(): 以数组的形式返回枚举成员
        TestEnum[] testEnums = TestEnum.values();
        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i]);
        }
        for (int i = 0; i < testEnums.length; i++) {
            //ordinal() :返回对应枚举成员的索引值
            System.out.println(testEnums[i].ordinal());
        }
        //把字符串转化为枚举实例
        TestEnum color = TestEnum.valueOf("RED");
        System.out.println(color);
        //比较两个枚举在定义时的顺序
        System.out.println(RED.compareTo(BLACK));
    }
    public static void main01(String[] args) {
        TestEnum color = RED;

        switch (color) {
            case RED:
                System.out.println("RED");
                break;
            case BLACK:
                System.out.println("BLACK");
                break;
            default:
                System.out.println("error");
                break;
        }
    }
}
